package com.uhylab.uhuvinetest.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;

import com.uhylab.uhuvinetest.R;

public class UHMediaPlayerActivity extends AppCompatActivity {

    private VideoView vv_player;


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_uhmedia_player);


        vv_player = (VideoView) findViewById(R.id.vv_player);

        String uri = "android.resource://" + getPackageName() + "/" + R.raw.guide_android;
        vv_player.setVideoURI(Uri.parse(uri));
        vv_player.start();

        vv_player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                showDialog();
            }
        });

    }

    public void showDialog() {
        new AlertDialog.Builder(this)
                .setMessage("您看清楚了么？")
                .setPositiveButton("再来一遍", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        vv_player.start();
                    }
                })
                .setNegativeButton("结束", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).show();
    }
}
